package com.googlecode.mhtetris.tetris
{
	import away3d.containers.ObjectContainer3D;
	import away3d.materials.ColorMaterial;
	import away3d.materials.methods.SoftShadowMapMethod;
	import away3d.primitives.Cube;
	
	import com.googlecode.mhtetris.Main3D;
	
	import flash.display.Sprite;
	import flash.filters.GlowFilter;

	public class Block extends ObjectContainer3D
	{
		private static var matBase:ColorMaterial;
		
		private static var inc:int = 0;
		
		private var _cube:Cube;
		
		/* bloc statique : initialise le material partagés par tous les blocs */
		{
			matBase = new ColorMaterial(0xEE8659);
			matBase.ambient = 50;
			//matBase.smooth = true;
			matBase.lights = Main3D.getLigths();
			matBase.shadowMethod = Main3D.shadow;
		}
		
		public function Block(taille:int = 20)
		{
			
			/*graphics.beginFill(0xFF0000);
			//graphics.beginFill( (  (uint(Math.random()*255)) << 16    ) | (   (uint(Math.random()*255)) << 8   ) | (   uint(Math.random()*255)    ));
			graphics.drawRect(0,0,taille,taille);
			
			var filter:GlowFilter = new GlowFilter(0x770000, 1, 2, 2, 70, 10, true);
			this.filters = [filter];*/
			
			
			/*matBase = new ColorMaterial(0xEE8659);
			matBase.ambient = 50;
			//matBase.smooth = true;
			matBase.lights = Main3D.getLigths();
			matBase.shadowMethod = Main3D.shadow;*/
			
			
			//matBase.specular = 1;
			// --- les objets
			// -- le cube	
			_cube = new Cube(matBase, Tetris3D.LARGEUR_BLOCK_PX, Tetris3D.LARGEUR_BLOCK_PX, Tetris3D.LARGEUR_BLOCK_PX);
			//_cube.name = "cube : "+inc++;
			//_cube.extra = "cube extra : "+inc;
			_cube.castsShadows = true;
			_cube.x =  Tetris3D.LARGEUR_BLOCK_PX/2;
			_cube.y =  Tetris3D.LARGEUR_BLOCK_PX/2;
			//cube.z = -cube.height/2;
			addChild(_cube);
			
		}
		
		
		public function get cube():Cube
		{
			return _cube;
		}

		public function set cube(value:Cube):void
		{
			_cube = value;
		}

		/* pour que le gc libere de la mémoire */
		public function deleteCube():void {
			_cube.material = null;
			_cube.dispose(true);
			_cube = null;
		}
	}
}